package system.student.login.impl;

import org.apache.ibatis.annotations.Mapper;
import system.student.entity.user.Student;
import system.student.entity.user.Teacher;
import system.student.entity.user.UserInfo;
import system.student.entity.user.UserType;
import system.student.login.SignupStrategy;
import system.student.mapper.StudentMapper;
import system.student.mapper.TeacherMapper;
import system.student.mapper.UserMapper;
import system.student.util.MapperUtil;

import java.util.Scanner;

public class StudentSignupStrategyImpl implements SignupStrategy {
    private static final StudentMapper studentMapper = MapperUtil.getMapper(StudentMapper.class);
    private static final UserMapper userMapper = MapperUtil.getMapper(UserMapper.class);
    @Override
    public void signup(UserInfo userInfo) {
        String name;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学生的基本信息：" +
                "1.学生姓名" +
                "2.学生年龄" +
                "3.学生性别");
        System.out.println("请输入学生的姓名：");
        name = scanner.nextLine();
        System.out.println("请输入学生的年龄：");
        int age = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入学生的性别：");
        String gender = scanner.nextLine();
        Student student = new Student(userInfo, name, age, gender);
        try{
            userMapper.register(userInfo);
            Long userId = userInfo.getId();
            student.setUserId(userId);
            studentMapper.register(student);
        } catch (Exception e) {
            System.out.println("当前的错误是:"+ e.getMessage().split(" ")[2]);
            System.out.println(e.getMessage());
        }
        System.out.println("学生用户注册成功");
    }

    @Override
    public UserType getUserType() {
        return UserType.Teacher;
    }
}
